/**
 * @author monirul
 */


goog.require('goog.dom');

var SelfPlayerDeckView =  Class.create(PlayerDeckView,{
	
	initialize: function($super){
		$super();
		this._maxNoEquipement = 5;
	},
	
	init:function($super,o){
		$super(o);
		var _this = this;
		
		 this._model.playerCardListUpdated.attach(function () {
		    	_this.updateCardList();
		    });
		 this._model.gameCardDroped.attach(function () {
		    	_this.updateAfterDropCard();
		    });
	},
	
	
	updateRole:function(){
		this._roleElement = $(this.playerId +"_role");
		this._roleElement.innerHTML = this._model.getRole();
		$('btnGetRole').disabled = "disabled";
		$("btnGetCharacter").disabled = "";
		
	},
	
	readyToStart:function(){
		$('btnGetRole').disabled = "";
		//this._roleElement.innerHTML = this._model.getCharacter();
	},
	
	updateAfterDropCard:function(){
		var targetLocation = $(this.playerId +"_gameCardDeck");
		goog.dom.removeChildren(targetLocation);
		this.updateCardList();
	},
	
	updateCardList:function(){
		var cardList = this._model.getCardModelList();
		var playerId = this._model.getPlayerId();
		var _this = this;
		for(var i=0;i<cardList.length;i++){
			var card = cardList[i];
			var conf ={};
			conf.parentId = playerId+'_gamecard_'+i;
			this._initGameCardSpace(conf.parentId);
			conf.id = playerId+'_gamecard_'+i;
			conf.className = 'cardDisableClass';
			conf.width = '100%';
			conf.height = '100%';
			conf.playerId = this.playerId;
			conf.model = this._model;
			conf.controller = '';
			conf.elements = '';
			
			var init = {};
			init.model = card;
			init.controller = this._controller;
			init.elements = null;
			init.conf = conf;
			var cardView = new GameCardView();
			cardView.init(init);
			card.initializeCard();

		}
	},
	
	_initGameCardSpace:function(divid){
		if(!$(divid)){
			goog.dom.appendChild(this.gameCardDeck,goog.dom.createDom('div', {'style': this.gameCardStyle,'id':divid},''));
		}
	},
	
	_initDom: function(){
		this.playerId = this._model.getPlayerId();
		var player = this._model.getPlayer();
		this.equipementCards = [];
		this.armStyle = "height: 80%;width:15%;background-color: #003300;border: 2px;float:left;margin: 2px;";
		this.equipementDeck  = goog.dom.createDom('div', {'style': 'width:100%;height:40%','id':this.playerId +"_equipement"},'');
		for(var i=0;i<this._maxNoEquipement;i++){
			//var element = goog.dom.createDom('div', {'style': armStyle,'id':this.playerId+'_arm_'+i},'')
			//this.equipementCards.push(goog.dom.createDom('div', {'style': armStyle,'id':this.playerId+'_arm_'+i},''));//);
			goog.dom.appendChild(this.equipementDeck,goog.dom.createDom('div', {'style': this.armStyle,'id':this.playerId+'_arm_'+i},''));
		}
//		
		this.lifeCountBar = [];
		this.lifeCountPanel  = goog.dom.createDom('div', {'style': '','id':this.playerId +"_lifeCountPanel"},'');
		var hpStyle = "height: 10px;width:10px;border: 2px;float:left;margin: 2px;background-color:#FF0000";
		for(var i=0;i<this._model.getLifeCount();i++){
			//this.lifeCountBar.push(goog.dom.createDom('div', {'style': hpStyle,'id':this.playerId+'_hp_'+i},''));
			goog.dom.appendChild(this.lifeCountPanel, goog.dom.createDom('div', {'style': hpStyle,'id':this.playerId+'_hp_'+i},''));
		}
//		
		this.gameCardsOppositeSide = [];
		this.gameCardDeck  = goog.dom.createDom('div', {'style': 'width:100%;height:40%','id':this.playerId +"_gameCardDeck"},'');
		this.gameCardStyle = "height:80%;width:15%;background-color: green;border: 2px;float:left;margin: 2px;";
		for(var i=0;i<this._model.getCardCount();i++){
//			this.gameCardsOppositeSide.push(goog.dom.createDom('div', {'style': gameCardStyle,'id':this.playerId+'_gamecard_'+i},''));
			//goog.dom.appendChild(this.gameCardDeck,goog.dom.createDom('div', {'style': this.gameCardStyle,'id':this.playerId+'_gamecard_'+i},''));
		}
//		
		this.name  = goog.dom.createDom('span', {'id':this.playerId +"_name",'style':'padding:0px;float:right;word-wrap: break-word '},this._model.getPlayer().name);
		this.role  = goog.dom.createDom('span', {'id':this.playerId +"_role",'style':'padding:0px;float:right;word-wrap: break-word '},this._model.getRole());
		this.character  = goog.dom.createDom('span', {'id':this.playerId +"_character",'style':'padding:0px;float:right;word-wrap: break-word '},this._model.getCharacter());
		
		this.userRoleCharacterPanel  = goog.dom.createDom('div', {'style':'width:100%,height:30%;float','id':''},this.role,this.character);
		
		
		this.userDetail  = goog.dom.createDom('div', {'style': 'width:100%;;height:20%','id':this.playerId +"_userDetailDeck"},this.lifeCountPanel,this.name);
		
		
		this.btnOk  = goog.dom.createDom('input', {'type':'button','style':this.playerId +"_",'id':'btnOk','value':'Ok'},'Ok');
		this.btnCancel  = goog.dom.createDom('input', {'type':'button','style':this.playerId +"_",'id':'btnCancel','value':'Cancel'},'Cancel');
		//this.actionPanel  = goog.dom.createDom('div', {'style':this.playerId +"_action",'id':'btnOk'},'Ok');
		this.actionPanel  = goog.dom.createDom('div', {'style':'width:100%,height:60%;float','id':''},this.btnOk,this.btnCancel);
		this.userActionPanel = goog.dom.createDom('div', {'style': 'width:20%;;height:100%;float:right','id':this.playerId +"_userActionDeck"},this.userRoleCharacterPanel,this.actionPanel);
		
		
		this.playerDeck  = goog.dom.createDom('div', {'style': 'border:1px sloid red;width:75%;;height:100%','id':this.playerId +"_playerDeck"},this.equipementDeck,this.userDetail,this.gameCardDeck);
		this.selfPlayerDeck  = goog.dom.createDom('div', {'style': 'border:1px sloid red;width:100%;;height:100%','id':this.playerId +"_playerDeck"},this.playerDeck ,this.userActionPanel);
		this._targetLocation = $(this._elements.targetLocation);
		goog.dom.appendChild(this._targetLocation, this.selfPlayerDeck);
		
		
		this._btnOk = new goog.ui.Button();
		this._btnOk.decorate(goog.dom.$('btnOk'));
		this._btnCancel = new goog.ui.Button();
		this._btnCancel.decorate(goog.dom.$('btnCancel'));
		
		var _controller = this._controller;
		goog.events.listen(this._btnOk, goog.ui.Component.EventType.ACTION,
		        function(e) {
		    		_controller.okClicked();
		});
		
		goog.events.listen(this._btnCancel, goog.ui.Component.EventType.ACTION,
		        function(e) {
		    		_controller.cancelClicked();
		});
		
		
//		this._targetLocation.appendChild(this.playerDeck);
	},
	
	show : function () {
        this.rebuild();
	},
	
	
	
	rebuild: function() {
		this._initDom();
	}
	
});
